class SSHConnection {
  final String id;
  final String name;
  final String host;
  final int port;
  final String username;
  final String? password;
  final String? privateKeyPath;
  final String? passphrase;
  final DateTime lastUsed;
  final int usageCount;

  SSHConnection({
    required this.id,
    required this.name,
    required this.host,
    this.port = 22,
    required this.username,
    this.password,
    this.privateKeyPath,
    this.passphrase,
    DateTime? lastUsed,
    this.usageCount = 0,
  }) : lastUsed = lastUsed ?? DateTime.now();

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'name': name,
      'host': host,
      'port': port,
      'username': username,
      'password': password,
      'privateKeyPath': privateKeyPath,
      'passphrase': passphrase,
      'lastUsed': lastUsed.toIso8601String(),
      'usageCount': usageCount,
    };
  }

  factory SSHConnection.fromMap(Map<String, dynamic> map) {
    return SSHConnection(
      id: map['id'],
      name: map['name'],
      host: map['host'],
      port: map['port'],
      username: map['username'],
      password: map['password'],
      privateKeyPath: map['privateKeyPath'],
      passphrase: map['passphrase'],
      lastUsed: DateTime.parse(map['lastUsed']),
      usageCount: map['usageCount'],
    );
  }

  SSHConnection copyWith({
    String? id,
    String? name,
    String? host,
    int? port,
    String? username,
    String? password,
    String? privateKeyPath,
    String? passphrase,
    DateTime? lastUsed,
    int? usageCount,
  }) {
    return SSHConnection(
      id: id ?? this.id,
      name: name ?? this.name,
      host: host ?? this.host,
      port: port ?? this.port,
      username: username ?? this.username,
      password: password ?? this.password,
      privateKeyPath: privateKeyPath ?? this.privateKeyPath,
      passphrase: passphrase ?? this.passphrase,
      lastUsed: lastUsed ?? this.lastUsed,
      usageCount: usageCount ?? this.usageCount,
    );
  }
}